<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //将每一个字符取出来 用作对象的键 次数用作值
    var str = 'aabccd'
    var obj = {}
    for (var i in str) {
      var key = str[i];
      if (obj[key] === undefined) {
        // 说明该字符还没有出现
        obj[key] = 1;
      } else {
        obj[key] += 1;
      }
    }
    console.log(obj)
  </script>
</body>

</html>